home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / ubppmpqs.zip / ppmp4b.asm < prev    next >
Assembly Source File  |  1992-05-10  |  10KB  |  709 lines

  1. ;PPMP4b.ASM 2.0
  2. ;    MACHINE LANGUAGE SUBROUTINES
  3. ;    FOR PPMPQS
  4. ;    1991/92 by YUJI KIDA
  5. ;
  6. .386P
  7.  
  8. code    segment    use16
  9.     assume    cs:code,ds:code
  10.  
  11.     INCLUDE    UBP.MAC
  12.     include    ppmp.h
  13.  
  14. org    100h
  15.  
  16. start:
  17.  
  18. ; branch
  19.  
  20.     MOV_AX    AR0        ;ARRAY[0] is the command
  21.     MOV    BX,OFFSET CMD_TBL
  22.     SHL    AX,1
  23.     ADD    BX,AX
  24.     JMP    CS:[BX]
  25.  
  26. CMD_TBL:
  27.     dw    INITIALIZE,SETMATRIX
  28.  
  29.     even
  30. spmem        dw    ?
  31. ssmem        dw    ?
  32.  
  33. drv_off        dw    ?
  34. drv_seg        dw    ?
  35.  
  36. FBsize        dw    ?        ;size of original FactorBase
  37. MATsize        dw    ?        ;size of matrix
  38. ROWSsize    dw    ?        ;number of ROW data
  39.  
  40. histhandle    dw    ?
  41. RFBhandle    dw    ?
  42. ROWShandle    dw    ?
  43. decomphandle    dw    ?
  44.  
  45. handle1        dw    ?
  46. size1        dw    ?
  47. handle2        dw    ?
  48.  
  49. FBmemberID    dw    ?
  50. MATmemberID    dw    ?
  51.  
  52. matrixrightbase    dw    ?
  53. databuffer    dw    ?
  54.  
  55.  
  56.     align    4
  57. XMEMsize        dd    ?
  58. RFBbase            dd    ?
  59. ROWSbase        dd    ?
  60. decompdatabase        dd    ?
  61. decomppointerbase    dd    ?
  62. historybase        dd    ?
  63. freebase        dd    ?
  64.  
  65. totaloperations        dd    ?
  66.  
  67. ;
  68. ; set matrix
  69. ;
  70. ;command#=1
  71.  
  72. setmatrix:
  73.     mov    ax,cs
  74.     mov    ds,ax
  75.     mov    es,ax
  76.     mov    [spmem],sp
  77.  
  78.     mov    ax,[MATsize]
  79.     mov    cx,[ROWSsize]
  80.     cmp    cx,ax
  81.     jbe    short setmat5
  82.     mov    cx,ax
  83. setmat5:
  84.     xor    dx,dx            ;MATmemberID counter
  85.     mov    ebx,[ROWSbase]
  86. setmat10:
  87.     push    cx
  88.     push    dx
  89.     push    ebx
  90.     mov    ax,fs:[ebx]
  91.     mov    [FBmemberID],ax
  92.     mov    [MATmemberID],dx
  93.  
  94.     call    clear3rdbuffer
  95.     call    backsubstitution
  96.     call    clear2ndbuffer
  97.     call    set2ndpart
  98.     call    clear1stbuffer
  99.     call    set1stpart
  100.     call    writethisrow
  101.  
  102. setmat20:
  103.     pop    ebx
  104.     add    ebx,2
  105.     pop    dx
  106.     inc    dx
  107.     pop    cx
  108.     loop    setmat10
  109.  
  110.     call    fillrests
  111.  
  112.     call    closefiles
  113.  
  114.     mov    ax,ss
  115.     mov    ds,ax
  116.     mov    es,ax
  117.     retf
  118.  
  119.  
  120. fillrests:
  121.     mov    cx,[MATsize]
  122.     sub    cx,[ROWSsize]
  123.     jbe    short fillrestsret
  124.     mov    dx,[ROWSsize]
  125. fillrests10:
  126.     push    cx
  127.     push    dx
  128.     mov    [MATmemberID],dx
  129.     call    clear2ndbuffer
  130.     call    clear1stbuffer
  131.     call    set1stpart
  132.     call    writethisrow
  133.     pop    dx
  134.     inc    dx
  135.     pop    cx
  136.     loop    fillrests10
  137. fillrestsret:
  138.     ret
  139.  
  140.  
  141. backsubstitution:
  142.     mov    bx,[databuffer]
  143.  
  144.     mov    di,[FBmemberID]        ;initial set unit vector
  145.     mov    cx,di
  146.     and    cl,7
  147.     shr    di,3
  148.     mov    al,1
  149.     shl    al,cl
  150.     xor    [di+bx],al
  151.  
  152.     mov    edx,[totaloperations]
  153.     mov    esi,edx
  154.     dec    esi
  155.     shl    esi,2
  156.     add    esi,[historybase]
  157. backsubst10:
  158.     mov    edi,fs:[esi]        ;lower = dest, higher = source
  159.     mov    cx,di
  160.     and    cl,7
  161.     shr    di,3
  162.     mov    al,1
  163.     shl    al,cl
  164.     test    [di+bx],al
  165.     jnz    short backsubst30
  166. backsubst20:
  167.     sub    esi,4
  168.     dec    edx
  169.     jnz    backsubst10
  170.     ret
  171.  
  172. backsubst30:
  173.     shr    edi,16        ;source
  174.     mov    cx,di
  175.     and    cl,7
  176.     shr    di,3
  177.     mov    al,1
  178.     shl    al,cl
  179.     xor    [di+bx],al
  180.     jmp    backsubst20
  181.  
  182.  
  183. set2ndpart:
  184.     mov    ebx,[decomppointerbase]
  185.     mov    si,[databuffer]
  186.     mov    cx,[FBsize]
  187.     shr    cx,4            ;1/16
  188. set2nd10:
  189.     push    cx
  190.     lodsw
  191.     push    si
  192.     mov    cx,16
  193. set2nd20:
  194.     shr    ax,1
  195.     jnc    set2nd30
  196.     push    ax
  197.     push    cx
  198.  
  199. countthisX:
  200.     mov    esi,fs:[ebx]        ;top of the decomposition data
  201.     mov    cx,fs:[esi]
  202.     jcxz    countthisret
  203. countthis10:
  204.     add    esi,2
  205.     movzx    eax,word ptr fs:[esi]
  206.     shl    eax,1
  207.     add    eax,[RFBbase]
  208.     mov    ax,fs:[eax]        ;RFB prime number
  209.     cmp    ax,0ffffh
  210.     je    short countthis20
  211.  
  212.     push    cx
  213.     mov    cl,al
  214.     and    cl,7
  215.     shr    ax,3
  216.     add    ax,[matrixrightbase]
  217.     mov    di,ax
  218.     mov    al,1
  219.     shl    al,cl
  220.     xor    [di],al
  221.     pop    cx
  222.  
  223. countthis20:
  224.     loop    countthis10
  225. countthisret:
  226.  
  227.     pop    cx
  228.     pop    ax
  229. set2nd30:
  230.     add    ebx,4
  231.     loop    set2nd20
  232.     pop    si
  233.     pop    cx
  234.     loop    set2nd10
  235.     ret
  236.  
  237.  
  238.  
  239.  
  240. set1stpart:
  241.     mov    ax,[MATmemberID]
  242.     mov    cl,al
  243.     and    cl,7
  244.     shr    ax,3
  245.     add    ax,offset BUFFER
  246.     mov    di,ax
  247.     mov    al,1
  248.     shl    al,cl
  249.     mov    [di],al
  250.     ret
  251.  
  252.  
  253. clear1stbuffer:
  254.     mov    di,offset BUFFER
  255. clearbuffer10:
  256.     mov    cx,[MATsize]
  257. clearbuffer20:
  258.     shr    cx,5            ;1/32
  259.     xor    eax,eax
  260.     rep    stosd
  261.     ret
  262. clear2ndbuffer:
  263.     mov    di,[matrixrightbase]
  264.     jmp    clearbuffer10
  265. clear3rdbuffer:
  266.     mov    di,[databuffer]
  267.     mov    cx,[FBsize]
  268.     jmp    clearbuffer20
  269.  
  270.  
  271. writethisrow:
  272.     mov    dx,offset BUFFER
  273.     mov    cx,[MATsize]
  274.     shr    cx,2            ;*2/8
  275.     mov    ax,[MATmemberID]
  276.     mov    bx,[handle1]
  277.     cmp    ax,[size1]
  278.     jb    short setrow100
  279.     mov    bx,[handle2]
  280. setrow100:
  281.     mov    ah,40h            ;write data
  282.     int    21h
  283.     jc    diskerror
  284.     ret
  285.  
  286. ;
  287.  
  288. closefiles:
  289.     mov    ax,cs
  290.     mov    ds,ax
  291.  
  292.     mov    bx,[histhandle]
  293.     or    bx,bx
  294.     jz    short closef10        ;not opened
  295.     mov    ah,3eh            ;close file
  296.     int    21h
  297. closef10:
  298.     mov    bx,[handle1]
  299.     or    bx,bx
  300.     jz    short closef20        ;not opened
  301.     mov    ah,3eh            ;close file
  302.     int    21h
  303. closef20:
  304.     mov    bx,[handle2]
  305.     or    bx,bx
  306.     jz    short closef30        ;not opened
  307.     mov    ah,3eh            ;close file
  308.     int    21h
  309. closef30:
  310.     ret
  311.  
  312.  
  313. ;
  314. ;* Initialize
  315. ;
  316. ;COMMAND#=0
  317.  
  318. ;    V1 = datadrive
  319. ;    V2 = mebers
  320. ;    V3 = maxlength
  321. ;    V4 = minlength
  322. ;    V5 = totallength
  323.  
  324. INITIALIZE:
  325.     mov    ax,cs
  326.     mov    ds,ax
  327.     mov    es,ax
  328.  
  329.     mov    [spmem],sp
  330.  
  331.     MOV    BX,V1        ;adr of drv
  332.     MOV    AX,[BX]
  333.     MOV    [drv_OFF],AX
  334.     MOV    AX,[BX+2]
  335.     MOV    [drv_SEG],AX
  336.  
  337.     xor    eax,eax
  338.     mov_ax    AR1
  339.     shl    eax,10
  340.     mov    [XMEMsize],eax
  341.  
  342.     mov_ax    AR2
  343.     shl    ax,1
  344.     mov    [MATsize],ax
  345.  
  346.     shr    ax,3
  347.     mov    bx,offset BUFFER
  348.     add    bx,ax
  349.     mov    [matrixrightbase],bx
  350.     add    bx,ax
  351.     mov    [databuffer],bx
  352.  
  353.     call    setPROTECTfs
  354.  
  355.     call    getRFB
  356.     call    getROWS
  357.     call    getDECOMPDATA
  358.     call    gethistDATA
  359.     call    createMATRIXfiles
  360.     mov    eax,[XMEMsize]
  361.     add    eax,pmodeworkadr
  362.     cmp    eax,[freebase]
  363.     jb    short lackofmemory
  364. initout:
  365.     mov    ax,ss
  366.     mov    ds,ax
  367.     mov    es,ax
  368.     retf
  369.  
  370. diskerror:
  371.     mov    ax,8001h
  372. errorout:
  373.     mov    bx,AR0
  374.     mov    word ptr [bx],ax
  375.     mov    sp,[spmem]
  376.     call    closefiles
  377.     jmp    initout
  378.  
  379. initlackofdata:
  380.     mov    ax,8002h
  381.     jmp    errorout
  382. lackofmemory:
  383.     mov    ax,8003h
  384.     jmp    errorout
  385.  
  386.  
  387. getRFB:
  388.     mov    ax,3d00h        ;open for read
  389.     mov    dx,offset RFBfilename
  390.     int    21h
  391.     jc    diskerror
  392.     mov    [RFBhandle],ax
  393.  
  394.     mov    edi,pmodeworkadr
  395.     mov    [RFBbase],edi
  396. getRFB10:
  397.     mov    dx,offset BUFFER
  398.     mov    cx,400h            ;1024bytes unit
  399.     mov    bx,[RFBhandle]
  400.     mov    ah,3fh            ;read
  401.     int    21h
  402.     or    ax,ax
  403.     jz    short getRFBeof
  404.  
  405.     mov    cx,ax
  406.     shr    cx,1
  407.     mov    si,offset BUFFER
  408. getRFB20:
  409.     lodsw
  410.     mov    fs:[edi],ax
  411.     add    edi,2
  412.     loop    getRFB20
  413.     jmp    getRFB10
  414.  
  415. getRFBeof:
  416.     mov    eax,edi
  417.     add    eax,3
  418.     and    ax,0fffch
  419.  
  420.     mov    [ROWSbase],eax
  421.  
  422.     mov    eax,edi
  423.     sub    eax,[RFBbase]
  424.     shr    eax,1
  425.     mov    [FBsize],ax        ;original FBsize
  426.  
  427.     mov    ah,3eh            ;close file
  428.     mov    bx,[RFBhandle]
  429.     int    21h
  430.     ret
  431.  
  432. getROWS:
  433.     mov    ax,3d00h        ;open for read
  434.     mov    dx,offset ROWSfilename
  435.     int    21h
  436.     jc    diskerror
  437.     mov    [ROWShandle],ax
  438.  
  439.     mov    edi,[ROWSbase]
  440. getROWS10:
  441.     mov    dx,offset BUFFER
  442.     mov    cx,400h            ;1024bytes unit
  443.     mov    bx,[ROWShandle]
  444.     mov    ah,3fh            ;read
  445.     int    21h
  446.     or    ax,ax
  447.     jz    short getROWSeof
  448.  
  449.     mov    cx,ax
  450.     shr    cx,1
  451.     mov    si,offset BUFFER
  452. getROWS20:
  453.     lodsw
  454.     mov    fs:[edi],ax
  455.     add    edi,2
  456.     loop    getROWS20
  457.     jmp    getROWS10
  458.  
  459. getROWSeof:
  460.     mov    eax,edi
  461.     add    eax,3
  462.     and    ax,0fffch
  463.  
  464.     mov    [decompdatabase],eax
  465.  
  466.     mov    eax,edi
  467.     sub    eax,[ROWSbase]
  468.     shr    eax,1
  469.     mov    [ROWSsize],ax
  470.  
  471.     mov    ah,3eh            ;close file
  472.     mov    bx,[ROWShandle]
  473.     int    21h
  474.     ret
  475.  
  476.  
  477. getDECOMPDATA:
  478.     mov    si,offset decompfilename
  479.     call    setpathname
  480.     mov    dx,offset BUFFER
  481.     mov    ax,3d00h        ;open for read
  482.     int    21h
  483.     jc    diskerror
  484.     mov    [decomphandle],ax
  485.  
  486.     mov    edi,[decompdatabase]
  487. getdecomp10:
  488.     mov    dx,offset BUFFER
  489.     mov    cx,400h
  490.     mov    bx,[decomphandle]
  491.     mov    ah,3fh
  492.     int    21h
  493.     or    ax,ax
  494.     jz    short getdecompeof
  495.  
  496.     mov    cx,ax
  497.     shr    cx,1
  498.     mov    si,offset BUFFER
  499. getdecomp20:
  500.     lodsw
  501.     mov    fs:[edi],ax
  502.     add    edi,2
  503.     loop    getdecomp20
  504.     jmp    getdecomp10
  505.  
  506. getdecompeof:
  507.     mov    [decomppointerbase],edi
  508.  
  509.     mov    ah,3eh            ;close file
  510.     mov    bx,[decomphandle]
  511.     int    21h
  512.  
  513.     mov    ebx,[decomppointerbase]
  514.     mov    eax,[decompdatabase]
  515.     xor    edx,edx
  516. getdecomp100:
  517.     mov    fs:[ebx],eax
  518.     mov    dx,fs:[eax]
  519.     inc    dx
  520.     shl    dx,1
  521.     add    eax,edx
  522.     add    ebx,4
  523.     cmp    eax,[decomppointerbase]
  524.     jb    getdecomp100
  525.     add    ebx,3
  526.     and    bx,0fffch
  527.     mov    [historybase],ebx
  528.     ret
  529.  
  530.  
  531. gethistDATA:
  532.     mov    ax,3d00h        ;open for read
  533.     mov    dx,offset historyfilename
  534.     int    21h
  535.     jc    diskerror
  536.     mov    [histhandle],ax
  537.  
  538.     mov    edi,[historybase]
  539. gethist10:
  540.     mov    dx,offset BUFFER
  541.     mov    cx,400h
  542.     mov    bx,[histhandle]
  543.     mov    ah,3fh
  544.     int    21h
  545.     or    ax,ax
  546.     jz    short gethisteof
  547.  
  548.     mov    cx,ax
  549.     shr    cx,2
  550.     mov    si,offset BUFFER
  551. gethist20:
  552.     lodsd
  553.     mov    fs:[edi],eax
  554.     add    edi,4
  555.     loop    gethist20
  556.     jmp    gethist10
  557.  
  558. gethisteof:
  559.     mov    [freebase],edi
  560.     sub    edi,[historybase]
  561.     shr    edi,2            ;4bytes/unit
  562.     mov    [totaloperations],edi
  563.  
  564.     mov    ah,3eh            ;close file
  565.     mov    bx,[histhandle]
  566.     int    21h
  567.     ret
  568.  
  569. createMATRIXfiles:
  570.     mov    bx,offset MATRIXNAME1
  571.     MOV_AX    AR3
  572.     or    ax,ax
  573.     jz    short createmat10
  574.     sub    b